package com.sdgakj.web.user;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping(value="/customor")
public class CustomorController {
private static final String PAGE_SIZE = "10";
	
	/**
	 * 查询普通用户列表
	 * @param pageNumber  页号
	 * @param pageSize	  页的大小
	 * @param sortType	 排序字段
	 * @param model     返回的model
	 * @param request
	 * @return
	 *//*
	@RequestMapping(value="/list",method= RequestMethod.GET)
	public String listUser(@RequestParam(value = "page", defaultValue = "1") int pageNumber,
			@RequestParam(value = "page.size", defaultValue = PAGE_SIZE) int pageSize,
			@RequestParam(value = "sortType", defaultValue = "auto") String sortType, Model model,
			ServletRequest request) {

		Map<String,Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
		if(searchParams.get("GT_user.registerDate")!=null){
			searchParams.put("GT_user.registerDate", com.sdgakj.utils.DateUtil
					.formatStringToDate(searchParams.get("GT_user.registerDate") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"));
		}
		if (searchParams.get("LTE_user.registerDate") != null) {
			searchParams.put("LTE_user.registerDate", com.sdgakj.utils.DateUtil
					.formatStringToDate(searchParams.get("LTE_user.registerDate") + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
		}
		Page<Customor> customors =customorService.getCustomors(searchParams,pageNumber,pageSize,sortType);

		if (searchParams.get("GT_user.registerDate") != null) {
			searchParams.put("GT_user.registerDate",
					DateUtil.formatDateToString((Date) searchParams.get("GT_user.registerDate"), "yyyy-MM-dd"));
		} else {
			searchParams.put("GT_user.registerDate", "");
		}
		if (searchParams.get("LTE_user.registerDate") != null) {
			searchParams.put("LTE_user.registerDate",
					DateUtil.formatDateToString((Date) searchParams.get("LTE_user.registerDate"), "yyyy-MM-dd"));
		}else {
			searchParams.put("LTE_user.registerDate", "");
		}
		if(searchParams.get("EQ_user.code")!=null && StringUtils.isNotBlank(searchParams.get("EQ_user.code").toString())){
			if(searchParams.get("EQ_user.code").toString().trim().length()==5){
				searchParams.put("EQ_invitedcode", searchParams.get("EQ_user.code"));
				searchParams.remove("EQ_user.code");
			}
		}

		model.addAttribute("customors",customors);
		model.addAttribute("sortType", sortType);
		model.addAttribute("sortTypes", sortTypes);
		// 将搜索条件编码成字符串，用于排序，分页的URL
		model.addAttribute("searchParams", Servlets.encodeParameterStringWithPrefix(searchParams, "search_"));
		return "user/customorList";
	}
	*//**
	 * 删除用户信息
	 * @param id 用户id
	 * @param redirectAttributes 返回给前台的值
	 * @return
	 *//*
	@RequestMapping(value="/delete/{id}",method=RequestMethod.GET)
	public String deleteCustomor(@PathVariable("id")Long id,RedirectAttributes redirectAttributes){
		Customor customor =customorService.getCustomorById(id);
		customor.getUser().setDeltag(EnumIsDelete.DELETED.getCode()); //设置用户已经删除
		customorService.updateCustomor(customor);
		redirectAttributes.addAttribute("message", "删除成功！");

		return "redirect:/customor/list";
	}

	*//**
	 * 冻结用户
	 * @param id
	 * @param redirectAttributes
	 * @return
	 *//*
	@RequestMapping(value="/froze/{id}",method=RequestMethod.GET)
	public String frozeCustomor(@PathVariable("id")Long id,RedirectAttributes redirectAttributes){
		Customor customor =customorService.getCustomorById(id);
		customor.setStatus(EnumIsFrozen.FROZEN.getCode());
		customorService.updateCustomor(customor);
		redirectAttributes.addFlashAttribute("message", "冻结成功");

		return "redirect:/customor/list";
	}
	*//**
	 * 设置用户验证码
	 * @return
	 *//*
	@RequestMapping(value="/setcode",method=RequestMethod.GET)
	public String setcode(Model model){
		Random random = new Random();
		String sRand = "";
		for (int i = 0; i < 4; i++) {
			String rand = String.valueOf(random.nextInt(10));
			sRand += rand;
		}
		model.addAttribute("invitecode", sRand);
		return "user/sendCodeForm";
	}

	*//**
	 * 发送验证码
	 * @return
	 *//*
	@RequestMapping(value="/sendcode",method=RequestMethod.GET)
	@ResponseBody
	public String sendCode(@RequestParam(value="invitecode")String invitecode,
							@RequestParam(value="mobile",defaultValue="12345")String mobile){
		return userLoginService.sendCode(mobile, invitecode);
	}*/
}
